package cn.santi.service.impl;

import cn.santi.domain.Administrator;
import cn.santi.domain.SearchHistory;
import cn.santi.domain.User;
import cn.santi.domain.adminLog;
import cn.santi.mapper.SearchMapper;
import cn.santi.service.SearchService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SearchServiceImpl implements SearchService {
    @Autowired
    private SearchMapper sm;
    @Override
    public List<User> adminSearchUser(String content) {
        return sm.adminSearchUser(content);
    }

    @Override
    public void addSearchHistory(SearchHistory searchHistory) {
        sm.insert(searchHistory);
    }

    @Override
    public List<SearchHistory> adminGetSearch(int idAsInt, String page) {
        LambdaQueryWrapper<SearchHistory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SearchHistory::getSomeoneID,idAsInt).eq(SearchHistory::getPage,page);
        return sm.selectList(wrapper);
    }

    @Override
    public void adminDeleteSearch(int id, String page, String content) {
        LambdaQueryWrapper<SearchHistory> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SearchHistory::getSomeoneID,id).eq(SearchHistory::getPage,page).eq(SearchHistory::getContent,content);
        sm.delete(wrapper);
    }

    @Override
    public List<Administrator> adminSearchAdmin(String content) {
        return sm.adminSearchAdmin(content);
    }

    @Override
    public List<adminLog> adminSearchLog(String content) {
        return sm.adminSearchLog(content);
    }
}
